package com.zyw.dev.zyw.ui.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.zyw.dev.zyw.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MenuFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MenuFragment extends Fragment implements View.OnClickListener {

    private OnFragmentActionListener onFragmentActionListener;

    private Button btn_table, btn_chart;

    public MenuFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @return A new instance of fragment MenuFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static MenuFragment newInstance() {
        MenuFragment fragment = new MenuFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_menu, container, false);
        btn_table = (Button) view.findViewById(R.id.btn_table);
        btn_chart = (Button) view.findViewById(R.id.btn_chart);

        btn_table.setOnClickListener(this);
        btn_chart.setOnClickListener(this);
        return view;
    }

    public OnFragmentActionListener getOnFragmentActionListener() {
        return onFragmentActionListener;
    }

    public void setOnFragmentActionListener(OnFragmentActionListener onFragmentActionListener) {
        this.onFragmentActionListener = onFragmentActionListener;
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_table:
                if (onFragmentActionListener!=null){
                    onFragmentActionListener.onTableClicked();
                }
                break;
            case R.id.btn_chart:
                if (onFragmentActionListener!=null){
                    onFragmentActionListener.OnChartClicked();
                }
                break;
        }
    }

    public interface OnFragmentActionListener {
        void onTableClicked();
        void OnChartClicked();
    }

}
